package com.liesheng.haylou.ui.launch;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.liesheng.daemonlib.service.DaemonEnv;
import com.liesheng.haylou.R;
import com.liesheng.haylou.base.BaseActivity;
import com.liesheng.haylou.base.BaseVm;
import com.liesheng.haylou.base.PermissionListener;
import com.liesheng.haylou.bluetooth.BleManager;
import com.liesheng.haylou.databinding.ActivityLaunchBinding;
import com.liesheng.haylou.service.TraceServiceImpl;
import com.liesheng.haylou.ui.device.SearchDeviceActivity;
import com.liesheng.haylou.ui.main.MainActivity;
import com.liesheng.haylou.ui.setting.SetttingEqActivity;
import com.liesheng.haylou.view.dialog.ConfirmDialog;

import java.util.List;
import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;

/**
 * Date:2019/11/19
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 * 启动页面
 */
public class LaunchActivity extends BaseActivity<ActivityLaunchBinding, BaseVm> {

    //需要开启的相关权限
    private final String[] permissions = {Manifest.permission.ACCESS_COARSE_LOCATION};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
    }

    @Override
    protected ActivityLaunchBinding getmBinding() {
        mBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.activity_launch, null, false);
        return mBinding;
    }

    @Override
    protected boolean isFullScreen() {
        return true;
    }

    @Override
    protected BaseVm getViewModel() {
        return null;
    }

    @Override
    protected void initData() {
        showHeadLayout(false);

        TraceServiceImpl.sShouldStopService = false;
        DaemonEnv.startServiceMayBind(TraceServiceImpl.class);

        requestRunTimePermission(permissions, new PermissionListener() {
            @Override
            public void onGranted() {
                addSubscription(Observable
                        .timer(1000, TimeUnit.MILLISECONDS)
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Action1<Long>() {
                            @Override
                            public void call(Long aLong) {
                                MainActivity.startBy(LaunchActivity.this);
                                finish();
                            }
                        }));
            }

            @Override
            public void onGranted(List<String> grantList) {

            }

            @Override
            public void onDenied(List<String> denylist) {
                addSubscription(Observable
                        .timer(1000, TimeUnit.MILLISECONDS)
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(AndroidSchedulers.mainThread())
                        .subscribe(new Action1<Long>() {
                            @Override
                            public void call(Long aLong) {
                                MainActivity.startBy(LaunchActivity.this);
                                finish();
                            }
                        }));
            }
        });


    }

    @Override
    public void onClickView(View view) {
        switch (view.getId()) {
        }

    }

}
